OBJS_BOOTPACK = bootpack.o asmfunc.o hankaku.o fifo.o graphic.o dsctbl.o int.o mouse.o keyboard.o sprintf.o memory.o sheet.o timer.o mtask.o

all:
	make img
	make clean

%.bin: %.asm Makefile
	nasm $*.asm -o $*.bin

%.o: %.asm Makefile
	nasm -f elf32 $*.asm -o $*.o

%.o: %.c Makefile
	gcc -m32 -fno-stack-protector -c $*.c -o $*.o

bootpack.bin: $(OBJS_BOOTPACK) Makefile
	ld -m elf_i386 -e HariMain -Ttext 0x280000 $(OBJS_BOOTPACK) -o bootpack.bin

myos.sys: asmhead.bin bootpack.bin Makefile
	cat asmhead.bin bootpack.bin > myos.sys

img: ipl10.bin myos.sys Makefile
	dd if=/dev/zero of=os.img bs=512 count=2880
	dd if=ipl10.bin of=os.img bs=512 count=1 conv=notrunc
	sudo mount os.img /mnt/floppy -o loop
	sudo cp myos.sys /mnt/floppy
	sudo umount /mnt/floppy

clean:
	rm *.bin *.o *.sys
